﻿using System;
using System.Windows.Forms;

namespace D3Trader
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
            Trader.LoadConfig();
            RefreshValues();
        }

        private void RefreshValues()
        {
            lowBidTextBox.Text = Trader.LowBid.ToString();
            lowBuyTextBox.Text = Trader.LowBuy.ToString();
            highBidTextBox.Text = Trader.HighBid.ToString();
            highBuyTextBox.Text = Trader.HighBuy.ToString();
            socket1TextBox.Text = Trader.Socket1Modifier.ToString();
            socket2TextBox.Text = Trader.Socket2Modifier.ToString();
            socket3TextBox.Text = Trader.Socket3Modifier.ToString();
        }

        private void SaveValues()
        {
            Trader.LowBid = Convert.ToDouble(lowBidTextBox.Text);
            Trader.LowBuy = Convert.ToDouble(lowBuyTextBox.Text);
            Trader.HighBid = Convert.ToDouble(highBidTextBox.Text);
            Trader.HighBuy = Convert.ToDouble(highBuyTextBox.Text);
            Trader.Socket1Modifier = Convert.ToDouble(socket1TextBox.Text);
            Trader.Socket2Modifier = Convert.ToDouble(socket2TextBox.Text);
            Trader.Socket3Modifier = Convert.ToDouble(socket3TextBox.Text);
        }

        private void defaultSettingsButton_Click(object sender, EventArgs e)
        {
            Trader.LoadDefaultSettings();
            RefreshValues();
        }

        private void applyButton_Click(object sender, EventArgs e)
        {
            SaveValues();
            Trader.SaveConfig();
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveValues();
            Trader.SaveConfig();
            Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
